﻿using System;
using System.Xml.Serialization;
using CsvSerializer;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using ProtoBuf;

namespace dse_pe_parser
{
    [ProtoContract, JsonObject(MemberSerialization.OptIn)]
    public class PeRatio
    {
        private const int PROTO_OFFSET = 6451;

        [JsonProperty, ProtoMember((int) ColumnSerializationIndices.Symbol + PROTO_OFFSET),
         CsvField(FieldIndex = (int) ColumnSerializationIndices.Symbol)]
        public string Symbol { get; set; }

        [JsonProperty, JsonConverter(typeof (JavaScriptDateTimeConverter)), XmlElement(DataType = "date"),
         ProtoMember((int) ColumnSerializationIndices.EffectiveDate + PROTO_OFFSET),
         CsvField(FieldIndex = (int) ColumnSerializationIndices.EffectiveDate)]
        public DateTime EffectiveDate { get; set; }

        [JsonProperty, ProtoMember((int) ColumnSerializationIndices.PeLatest + PROTO_OFFSET),
         CsvField(FieldIndex = (int) ColumnSerializationIndices.PeLatest)]
        public decimal PeLatest { get; set; }

        [JsonProperty, ProtoMember((int) ColumnSerializationIndices.PeAudited + PROTO_OFFSET),
         CsvField(FieldIndex = (int) ColumnSerializationIndices.PeAudited)]
        public decimal PeAudited { get; set; }

        public override string ToString()
        {
            return string.Format("{0}, {1}, {2}", Symbol, PeLatest, PeAudited);
        }

        #region Nested type: ColumnSerializationIndices

        internal enum ColumnSerializationIndices
        {
            Symbol = 0,
            EffectiveDate,
            PeLatest,
            PeAudited
        }

        #endregion
    }
}